package com.kky.pp.popup

import android.app.Activity
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import com.custom.base.config.BaseConfig
import com.kky.pp.BuildConfig
import com.kky.pp.R
import com.kky.pp.util.SystemAppCallUtil
import io.rong.imkit.SpName
import razerdp.basepopup.BasePopupWindow

class FeedbackPopup(var ctx: Activity) : BasePopupWindow(ctx) {
    init {
        setContentView(R.layout.popup_feedback)
        initView()
    }

    private fun initView() {
        val dialogCancel = findViewById<TextView>(R.id.txtPopupFeedBackCancel)
        dialogCancel.setOnClickListener {
            dismiss()
        }
        val dialogConfirm = findViewById<TextView>(R.id.txtPopupFeedBackConfirm)
        val dialogContent = findViewById<TextView>(R.id.txtPopupFeedBackContent)
        val emailAddress = ctx.getString(R.string.email_address)
        val content = "Contact us at $emailAddress for more support, team will reply within 48 hours [Get help from Passion Pulse]"
        val sp = SpannableStringBuilder()
        sp.append(content)
        sp.setSpan(
            ForegroundColorSpan(ctx.getColor(R.color.color_F93E60)),
            sp.indexOf(emailAddress),
            sp.indexOf(emailAddress) + emailAddress.length,
            Spannable.SPAN_EXCLUSIVE_INCLUSIVE
        )
        dialogContent.text = sp

        dialogConfirm.setOnClickListener {
            val emailTitle = String.format(
                ctx.getString(R.string.send_email_default_title),
                BaseConfig.getInstance.getString(SpName.userCode, ""), BuildConfig.VERSION_NAME
            )
            SystemAppCallUtil().checkGmail(
                ctx,
                emailTitle,
                ctx.getString(R.string.send_email_default_txt)
            )
            dismiss()
        }
        setOutSideDismiss(true)
    }
}